package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @Author lvFF
 * @Date 2022/06/12/22:11;
 * Description
 */
@Controller
public class HelloController {
    @GetMapping("/basic")
    public String test(Model model) {


        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-basic";
    }
    @GetMapping("list")
    public String list(Model model){
        //小强
        Student student1 = new Student();
        student1.setName("小强");
        student1.setAge(18);
        student1.setMoney(1000.86f);
        student1.setBirthday(new Date());
        //小红
        Student student2 = new Student();
        student2.setName("小红");
        student2.setMoney(200.1f);
        student2.setAge(19);
        //将两个对象模型数据存放到List集合中
        List<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        //向model中存放List集合数据
        model.addAttribute("stus",list);


        HashMap<String, Student> map = new HashMap<>();
        map.put("student1",student1);
        map.put("student2",student2);

        // 3.1 向model中存放Map数据
        model.addAttribute("stusMap",map);
        return "02-list";
        //return null;
    }
}
